package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author DiXiaoNie
 * @since 2022/12/21 21:12
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    /**
     * wm新闻服务
     */
    @Autowired
    private WmNewsService wmNewsService;


    /**
     * 查询所有
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto) {

        return this.wmNewsService.findAll(dto);
    }

    /**
     * 提交--保存草稿--修改三合一
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {

        return this.wmNewsService.submit(dto);
    }

    /**
     * 回显文章
     *
     * @param id id
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @GetMapping("/one/{id}")
    public ResponseResult findNews(@PathVariable Integer id) {
        return this.wmNewsService.findNews(id);
    }

    /**
     * 删除文章
     *
     * @param id id
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Integer id) {
        return this.wmNewsService.deleteNews(id);
    }

    /**
     * 上架或下架
     *
     * @param wmNews wm新闻
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/23
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNews wmNews) {
       return this.wmNewsService.downOrUp(wmNews);
    }
}
